package com.smartfactory.sail.controller;


import com.ada.base.common.ApiResponse;
import com.ada.base.common.ControllerResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.smartfactory.sail.config.BizzException;
import com.smartfactory.sail.entity.ItemWorkingprocedurePicking;
import com.smartfactory.sail.service.IItemWorkingprocedurePickingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 工序领料记录 前端控制器
 * </p>
 *
 * @author 王巨壁
 * @since 2019-09-25
 */
@Api(tags = "工序领料")
@RestController
@RequestMapping("/item-workingprocedure-picking")
public class ItemWorkingprocedurePickingController extends ControllerResponse {

    private IItemWorkingprocedurePickingService iItemWorkingprocedurePickingService;

    public ItemWorkingprocedurePickingController(IItemWorkingprocedurePickingService iItemWorkingprocedurePickingService) {
        this.iItemWorkingprocedurePickingService = iItemWorkingprocedurePickingService;
    }

    @PostMapping("picking")
    @ApiOperation(value = "提交领料信息", notes = "提交领料信息")
    public ApiResponse<Object> picking(@RequestBody ItemWorkingprocedurePicking picking) {
        try {
            return ok(iItemWorkingprocedurePickingService.addPicking(picking));
        } catch (BizzException e) {
            return fail(e.getMessage());
        }
    }

    @PostMapping("history")
    @ApiOperation(value = "领料历史列表", notes = "领料历史列表")
    public ApiResponse<Object> history(@RequestBody ItemWorkingprocedurePicking picking) {
        QueryWrapper<ItemWorkingprocedurePicking> query = new QueryWrapper<>();
        query.setEntity(picking);
        return ok(iItemWorkingprocedurePickingService.list(query));
    }
}
